package org.example.methodreference;

import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

public class Java8MethodReference2 {
    public static void main(String[] args) {
        List<Employee> list = Arrays.asList(
                new Employee("mkyong", 38, BigDecimal.valueOf(3800)),
                new Employee("zilap", 5, BigDecimal.valueOf(100)),
                new Employee("ali", 25, BigDecimal.valueOf(2500)),
                new Employee("unknown", 99, BigDecimal.valueOf(9999)));
        System.err.println(JSONObject.toJSONString(list,true));
        ComparatorProvider provider = new ComparatorProvider();
        list.sort(provider::compareBySalary);
        System.err.println(JSONObject.toJSONString(list,true));
        list.sort(provider::compareByName);
        System.err.println(JSONObject.toJSONString(list,true));
        String[] stringArray = { "Barbara", "James", "Mary", "John","Patricia", "Robert", "Michael", "Linda" };
        Arrays.sort(stringArray,String::compareToIgnoreCase);
        System.err.println(JSONObject.toJSONString(stringArray));
    }
}

class ComparatorProvider{
    public int compareByAge(Employee e1,Employee e2){
        return e1.getAge().compareTo(e2.getAge());
    }

    public int compareByName(Employee e1,Employee e2){
        return e1.getName().compareTo(e2.getName());
    }

    public int compareBySalary(Employee e1,Employee e2){
        return e1.getSalary().compareTo(e2.getSalary());
    }

}
class Employee{
    private String name;
    private Integer age;
    private BigDecimal salary;

    public Employee(String name, Integer age, BigDecimal salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }

    public BigDecimal getSalary() {
        return salary;
    }
}
